package net.sourceforge.krama.tag.widget;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.sourceforge.krama.css.CSSLink;
import net.sourceforge.krama.css.CSSTemplate;
import net.sourceforge.krama.html.THTML;
import net.sourceforge.krama.html.child.HTMLLabel;
import net.sourceforge.krama.html.child.HTMLLink;
import net.sourceforge.krama.listener.TEventListener;
import net.sourceforge.krama.listener.TMouseListener;


public class TLink extends AbstractT {

	private String color;
	private String text;
	private String size;
	private String html;
	private String url;
	private String target;

	private CSSTemplate cssLink = new CSSTemplate();
	private HTMLLink htmlLink = new HTMLLink();

	private TImage image;
	
	private String parentName;

	private List<TEventListener> listenerList = new ArrayList<TEventListener>();

	private String name;

	public TLink(String text) {
		this.text = text;
	}
	
	public TLink(TImage image) {
		image.setParentName(name);
		image.draw();
		this.text = image.getHtml();
	}

	public String getHtml() {
		return html;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
		cssLink.setColor(color);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
		cssLink.setSize(size);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = "krama-" + name;
	}

	@Override
	public void draw() {
		// TODO Auto-generated method stub

		this.html = htmlLink.starDraw();
		this.html += text;
		this.html += htmlLink.endDraw();
	}

	public void addTMouseListener(TMouseListener mouseListener)
			throws IllegalArgumentException {
		// TODO Auto-generated method stub
		listenerList.add(mouseListener);
		String fonction = mouseListener.onClick();
		htmlLink.addClick(fonction);
	}

	public CSSTemplate getCssLink() {
		return cssLink;
	}

	public void setCssLink(CSSTemplate cssLink) {
		this.cssLink = cssLink;
	}

	public HTMLLink getHtmlLink() {
		return htmlLink;
	}

	public void setHtmlLink(HTMLLink htmlLink) {
		this.htmlLink = htmlLink;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	@Override
	public String getCSS() {
		return cssLink.getCSS("." + parentName + " ." + name);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
		htmlLink.setUrl(this.url);
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
		htmlLink.setTarget(target);
	}
}
